package everyday;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/6/24 10:42
 * 11. 盛水最多的容器
 * https://leetcode.cn/problems/container-with-most-water/
 */
public class Solution11 {

    // 利用单调性 + 双指针
    public int maxArea(int[] height) {
        int n = height.length;
        int left = 0, right = n - 1;
        int volume = Integer.MIN_VALUE;
        while (left < right) {
            // 更新最大体积
            volume = Math.max(volume, Math.min(height[left], height[right]) * (right - left));
            // 缩小区间
            if (height[left] > height[right]) {
                --right;
            } else {
                ++left;
            }
        }
        return volume;
    }
}
